package service;

import dao.GoodsDao;
import domain.Car;
import domain.Goods;
import domain.Page;

import java.util.ArrayList;
import java.util.List;

public class GoodsService {
    GoodsDao gdao = new GoodsDao();

    public List<Goods> findAll(String goods) {
        return gdao.findUserByName(goods);
    }

    public Goods findGoodsById(int id) {
        return gdao.findGoodsById(id);
    }

    public String findnum(String goods,String userid){
        return gdao.findnum(goods,userid);
    }

    public List<Car> findCarsByUserid (int userid){
        return gdao.findCarsByUserid(userid);
    }

    public List<Page> getPages(int user_id){
        int total = gdao.getTotal(user_id);
        int pageSize = gdao.pageSize;
        int pageCount = (total%pageSize==0?total/pageSize:total/pageSize+1);
        List<Page> pages=new ArrayList<Page>();
        for(int i=1;i<=pageCount;i++) {
            Page page=new Page();
            page.setPageNo(i);
            page.setPageText("No."+i);
            pages.add(page);
        }
        return pages;
    }
}
